var app = getApp();
var util = require('../../../../utils/util.js');
var api = require('../../../../config/api.js');
var pay = require('../../../../services/pay.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    trainInfo:null,
    trainId:0, 
    selectedId:'detail',
    tabNav: {
      list: [{
        id: 'detail',
        title: '签到记录'
      }, {
        id: 'plan',
        title: '培训计划'
      }, {
        id: 'contact',
        title: '联系方式'
      }],
      selectedId: 'detail'
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id != undefined){
      this.setData({
        trainId: parseInt(options.id)
      });
    }else if (options.sence){
      this.setData({
        trainId: parseInt(options.sence)
      });
    }
    this.getTrainInfo();
  },
  getTrainInfo: function () {
    let that = this;
    util.request(api.TeaTrainDetail + '?train_id=' + that.data.trainId).then(function (res) {
      if (res.code === 200) {
        that.setData({
          train: res.data.trainInfo
        });        
        
      }
    });
  },
  tabChange:function(e){
    this.setData({
      selectedId: e.detail     
    });
  },
  addToSign: function(){
    util.request(api.TrainSign, { train_id: this.data.trainId }, 'POST').then(res => {
      if (res.code == 200) {
        util.showSuccessToast("签到成功");
      } else {
        util.showErrorToast('签到失败');
      }
    });
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})